using NHibernate;
using NHibernate.Context;

namespace ThunderJob.Persistence.Storage
{
    public class WebSessionStorage : ISessionStorage
    {
        private ISessionFactory sessionFactory;

        public WebSessionStorage(ISessionFactory sessionFactory)
        {
            this.sessionFactory = sessionFactory;
        }

        public ISession GetSession()
        {
            return sessionFactory.GetCurrentSession();
        }

        public void SetSession(ISession session)
        {
            CurrentSessionContext.Bind(session);
        }

        public ISession DeleteSession()
        {
            return CurrentSessionContext.Unbind(sessionFactory);
        }
    }
}